//
//  ViewController.m
//  ImageTool
//
//  Created by Apple on 2017/6/5.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "ViewController.h"
#import "UIImage+ImageRotate.h"
#import "UIImage+ImageCut.h"
#import "UIView+imageScreenShot.h"
#import <QuartzCore/QuartzCore.h>
#import <Accelerate/Accelerate.h>
#import "UIImage+imageScaleSize.m"
#import "UIView+LSCore.h"

@interface ViewController ()
{
    UIImageView *image1;
}

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //self.view.backgroundColor = [UIColor blackColor];
    image1 = [[UIImageView alloc] init];
    image1.frame = CGRectMake(50, 50, 50, 50);
    
   
   
   
    image1.image = [UIImage imageNamed:@"timg.jpg"];
    [self.view addSubview:image1];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 300, 50, 30);
    btn.backgroundColor = [UIColor redColor];
    
    [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    }
-(void)btnClick
{
   // [self imageRotate];
    //[self imageCut];
    //[self imageScreen];
    
   //image1.image = [self blurryImage:image1.image withBlurLevel:0.8];
    
    //[self imageScale];
    
    [image1 addRoundedCorners:UIRectCornerTopLeft|UIRectCornerTopRight withRadii:CGSizeMake(5.0, 5.0)];

}
//图片旋转
- (void)imageRotate
{
    //UIImage *image = [UIImage imageNamed:@"timg.jpg"];
    UIImage *imageNew = [image1.image imageRotateIndegree:M_PI];
    //UIImageWriteToSavedPhotosAlbum(imageNew, nil, nil, nil);
    image1.image =imageNew;
    
    
}
- (void)imageCut
{
      UIImage *imageNew = [image1.image ImageCutSize:CGRectMake( 50 , 50, 320, 200)];
    image1.image = imageNew;
   
    //UIImageWriteToSavedPhotosAlbum(imageNew, nil, nil, nil);
}

//截屏

/**
    全屏截图
 */
- (void)imageScreen
{
    UIImage *imageNew = [self.view imageScreenShot ];
    UIImageWriteToSavedPhotosAlbum(imageNew, nil, nil, nil);
}
-(void)imageScale
{
    UIImage *imageNew = [image1.image scaleImage:image1.image toScale:0.1];
    image1.image = imageNew;
}


//颜色转图片

-(UIImage *)ImageForColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 10, 10);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}
-(UIImage *)blurryImage:(UIImage *)image
          withBlurLevel:(CGFloat)blur {
    
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *inputImage = [CIImage imageWithCGImage:image.CGImage];
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"
                                  keysAndValues:kCIInputImageKey, inputImage,
                        @"inputRadius", @(blur),
                        nil];
    
    CIImage *outputImage = filter.outputImage;
    CGImageRef outImage = [context createCGImage:outputImage
                                        fromRect:[outputImage extent]];
    
    return [UIImage imageWithCGImage:outImage];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
